﻿using System.Collections.ObjectModel;
using MvpFramework;
using MvpFramework.Infastructure;
using MvpFramework.Specifications;
using NUnit.Framework;
using Rhino.Mocks;

namespace GersonLehrman.Experts.UnitTests.Infrastructure
{
    [TestFixture]
    public class SpecificationManagerTestFixture : AssertionHelper
    {
        private SpecificationManager _validationManager;
        private ReadOnlyCollection<Specification<ITestView>> _failedSpecs;
        private MockRepository _mocker;
        private ITestView _view;
        private ReadOnlyCollection<Specification<ITestView>> _passedSpecs;

        private void Arrange()
        {
            _mocker = new MockRepository();
            _view = _mocker.DynamicMock<ITestView>();
            _validationManager = new SpecificationManager();
        }

        [Test]
        public void GetFailedSpecifications_returns_correct_results()
        {
            Arrange();
            //Act
            _failedSpecs = _validationManager.GetFailedSpecifications(_view);
            //Assert
            Assert.That(_failedSpecs.Count == 1);
            Assert.That(_failedSpecs[0].GetType() == typeof (TestViewAlwaysFalseSpecification));
        }

        [Test]
        public void GetPassedSpecifications_returns_correct_results()
        {
            Arrange();
            //Act
            _passedSpecs = _validationManager.GetPassedSpecifications(_view);
            //Assert
            Assert.That(_passedSpecs.Count == 1);
            Assert.That(_passedSpecs[0].GetType() == typeof(TestViewAlwaysTrueSpecification));
        }
    }
}

namespace GersonLehrman.Experts.UnitTests
{
    public interface ITestView:IMvpView
    {
    }

    public class TestViewAlwaysFalseSpecification : Specification<ITestView>
    {
        public override bool IsSatisfiedBy(ITestView obj)
        {
            return false;
        }
    }

    public class TestViewAlwaysTrueSpecification : Specification<ITestView>
    {
        public override bool IsSatisfiedBy(ITestView obj)
        {
            return true;
        }
    }
}